package com.easylinkin.linkappapi.lobar.controller;

import com.easylinkin.linkappapi.lobar.entity.UserProject;
import com.easylinkin.linkappapi.lobar.service.UserProjectService;
import com.easylinkin.linkappapi.lobar.vo.UserProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestMessage;

/**
 * @author zhengwen
 **/
@RestController
@RequestMapping("/appUserProject")
@Api(tags = "项目用户管理App端接口")
public class AppUserProjectController {

    @Autowired
    private UserProjectService userProjectService;

    /**
     * app通讯录（数据来源花名册）
     *
     * @param userProjectVo 项目花名册vo
     * @return 统一出参
     */
    @PostMapping("/appAddressBook")
    @ApiOperation("根据条件获取通讯录数据查询")
    public RestMessage appAddressBook(@RequestBody UserProjectVo userProjectVo) {
        UserProject userProject = userProjectVo.getUserProject();
        if (userProject == null) {
            userProjectVo.setUserProject(new UserProject());
        } else if (StringUtils.isNotBlank(userProject.getType())) {
            //按工人匹配(1管理人员，2作业人员, 3其他人员)
            String[] s = {"", "管理人员", "作业人员", "其他人员"};
            userProject.setWorkType(s[Integer.valueOf(userProject.getType())]);
            //type清空
            userProject.setType(null);
        }
        return userProjectService.appAddressBook(userProjectVo);
    }

    /**
     * 获取人员下拉框选择数据
     *
     * @return site.morn.rest.RestMessage
     * @author Jereay
     * @date 2024/5/16 10:27
     */
    @ApiOperation(value = "获取人员下拉框选择数据", notes = "获取人员下拉框选择数据", httpMethod = "GET")
    @GetMapping("/queryProjectUserSelect")
    public RestMessage queryProjectUserSelect() {
        return this.userProjectService.queryProjectUserSelect();
    }

}
